import { eventFormat, bindEvent } from './compiler/event.js'
import { stateFormat }  from './compiler/state.js'
function useDom({ template, state, methods }, el) {

    
    el.innerHTML = render(template, state)   
    
    bindEvent(methods,state)
   
    
}

function render(template, state) {
    
    template = eventFormat(template)     
    template = stateFormat(template, state)
    console.log(333,template)
  return template
}

export function updateDom(statePool,key,val){ 
 
  const oItems = document.getElementsByTagName('*')    
  statePool.forEach(state => {
    
    for (let i=0; i<oItems.length; i++){
      let  oItem = oItems[i]     
       if (parseInt(oItem.dataset.dom) === state._flag){
         oItem.innerHTML = val
       }
    }
  });
}


export default useDom